package com.itqn.service.Impl;

import com.itqn.dao.Impl.ProductDaoImpl;
import com.itqn.dao.ProductDao;
import com.itqn.pojo.PageBean;
import com.itqn.pojo.Product;
import com.itqn.service.ProductService;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();


    @Override
    public Product findById(int id) throws Exception {
        return productDao.findById(id);
    }

    @Override
    public int addProduct(Product product) throws Exception {
        return productDao.addProduct(product);
    }

    @Override
    public int deleteGoods(int id) throws Exception {
        return productDao.deleteGoods(id);
    }

    @Override
    public int updateGoods(Product product) throws Exception {
        return productDao.updateGoods(product);
    }

    @Override
    public int deleteAll(String key) throws Exception {
        return productDao.deleteAll(key);
    }

    @Override
    public PageBean<Product> query(String name, Integer categoryId, Integer status, Integer pageSize, Integer page) throws Exception {
        PageBean pb = new PageBean();
        // 封装商品集合
        pb.setList(productDao.query(name, categoryId, status, pageSize, page));
        // 封装总条数
        Integer totalCount = productDao.totalCount(name, categoryId, status);
        pb.setTotalCount(totalCount);
        // 封装总页数
        pb.setPageCount(totalCount % pageSize == 0 ? totalCount / pageSize : (totalCount / pageSize + 1));
        return pb;
    }

    @Override
    public Integer count(Long categoryId) throws Exception {
        return productDao.count(categoryId);
    }

    @Override
    public void updatestatic(Product product) throws Exception {
        productDao.updatestatic(product);
    }
}
